package com.faiz;

import com.faiz.generic.SchoolClass;
import com.faiz.generic.Student;
import org.junit.Test;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class test {
    @Test
    public void test() {
        Student student = new Student("faiz", 23, 100, "M2020", SchoolClass.ONE, 12.5, true);
        List<Field> collect = Arrays.stream(student.getClass().getDeclaredFields()).collect(Collectors.toList());
        for (Field field : collect) {
            try {
                field.setAccessible(true);
                Object object = field.get(student);
                System.out.println(field.getName() + ":" + object.toString());
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }

    @Test
    public void testRef() {
        List<int[]> list = new ArrayList<>();
        int[] array = {1, 2, 3};
        list.add(array);
        list.stream().forEach(x -> {
            for (int num : x) {
                System.out.println(num);
            }
        });
       array[1] = 5;
        list.stream().forEach(x -> {
            for (int num : x) {
                System.out.println(num);
            }
        });
    }
}
